#!/usr/bin/env bash

#get this script real directory
SOURCE="$BASH_SOURCE"
while [ -h "$SOURCE"  ]; do # resolve $SOURCE until the file is no longer a symlink
    this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"
    SOURCE="$(readlink "$SOURCE")"
    # if $SOURCE was a relative symlink, 
    #we need to resolve it relative to the path 
    #where the symlink file was located
    [[ $SOURCE != /*  ]] && SOURCE="$this_script_dir/$SOURCE"
done
this_script_dir="$( cd -P "$( dirname "$SOURCE"  )" && pwd  )"

source $this_script_dir/tool_sh/assist/global.sh
log_level=info

################################################################################
#                                                                          80col
print_help()
{
    cat <<EOF
    useage:
      create one tarball: $0 --src_dir=your_dir


    --src_dir=your_dir  - directory that you want to tar 

    --log_level=<debug> - control pint log on streen,trace|debug|info|warn|error|critical

    --help  - prints help screen, script will exit after printing


EOF
}

#src_dir=$1
dst_dir=/mnt/c/Users/liujiaquan/git/tar

main()
{
    if [ $_arg_num_ -eq 0 ] || [ -n "$help" ] ; then
        print_help
        return 0;
    fi

	if [ -d $dst_dir ] ; then
		if [ -d $src_dir ] ; then
			tar -zcf $dst_dir/$(basename ${src_dir}).tar.gz	$src_dir
			vlogi "tar director \"$src_dir\" to $dst_dir/$(basename ${src_dir}).tar.gz"
		else
			vloge "src_dir is not exist, src_dir:$src_dir"
		fi
	else
		vloge "dst_dir is not exist, dst_dir:$dst_dir"
	fi

    return 0
}
main || exit 1 && exit 0
